package com.chenfan.magic.interpreter;

import com.chenfan.magic.entity.TTLModel;
import com.chenfan.magic.resolver._MainResolver;
import com.chenfan.magic.tags.TagScript;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * IDC 主解析引擎
 *
 * @author 周夕
 * @date 2020-02-24 18:44
 */
@Slf4j
@Data
public class _MainInterpreter {

    public Object run(Map<String, Object> idcRuntimePool, TTLModel ttlModel, String prefixKey, TagScript scriptModel, Map<String, Object> paramMap) {
        return __InterpreterBuilder.getInterpreter(idcRuntimePool, scriptModel.getLanguage())
                .run(idcRuntimePool, new _MainResolver().resolveScope(idcRuntimePool, ttlModel, prefixKey, scriptModel, paramMap), paramMap);
    }

    public Object run(Map<String, Object> idcRuntimePool, TTLModel ttlModel, String prefixKey, String language, String code, Map<String, Object> paramMap) {
        return __InterpreterBuilder.getInterpreter(idcRuntimePool, language)
                .run(idcRuntimePool, code, paramMap);
    }
}
